package com.gupaoedu.vip.pattern.factory.simplefactory;

import com.gupaoedu.vip.pattern.factory.ICourse;
import com.gupaoedu.vip.pattern.factory.JavaCourse;
import com.gupaoedu.vip.pattern.factory.PythonCourse;

/**
 * 小作坊式的工厂模型
 * Created by Tom.
 */
public class SimpleFactoryTest {

    public static void main(String[] args) {
        //1、传统new的方式来实例化
        ICourse course1 = new JavaCourse();
        course1.record();
        //2、简单工厂模式，根据不同参数来实例化不同的类型 相比较1更加简洁，不要来回去new
        CourseFactory factory = new CourseFactory();
        ICourse course = factory.create("java");
        course.record();
        ICourse python = factory.create("python");
        python.record();
        //3、同2换一个方式来实例化对象
        CourseFactory factory2 = new CourseFactory();
        ICourse javaCourse = factory2.createByClassName("com.gupaoedu.vip.pattern.factory.JavaCourse");
        javaCourse.record();
        //4\
        CourseFactory factory4 = new CourseFactory();
        ICourse python4 = factory4.createByClassObject(PythonCourse.class);
        python4.record();
    }
}
